package com.ncmmall.application.msm;

import com.feijin.commons.exceptions.InterfaceException;
import com.feijin.commons.lang.PropertiesHelps;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.fluent.Request;
import org.springframework.stereotype.Service;

/**
 * 短信发送
 *
 * @author linxs
 */
@Service
public class MsmService {

    /**
     * 短信发送
     *
     * @param mobile  手机号码
     * @param content 短信内容
     */
    public void send(String mobile, String content) {
        try {
            HttpResponse response = Request.Get(PropertiesHelps.getValue("SMS_URL") + "?username=" + PropertiesHelps.getValue("SMS_USERNAME") + "&password=" + PropertiesHelps.getValue("SMS_PASSWORD") + "&mobile=" + mobile + "&content=" + content + "&productid=" + PropertiesHelps.getValue("SMS_PRODUCT_ID"))
                    .execute()
                    .returnResponse();
            int status = response.getStatusLine().getStatusCode();
            if (status != HttpStatus.SC_OK) {
                throw new InterfaceException("非200响应码");
            }
        } catch (InterfaceException e) {
            throw e;
        } catch (Exception e) {
            throw new InterfaceException("接口异常", e);
        }
    }


}
